<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('路段列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								道路编码：<input type="text" name="roadcode"/>
							</li>

							<li>
								道路名称：<input type="text" name="roadname"/>
							</li>

							<li>
								所属乡镇：<input type="text" name="deptname" onclick="selectDeptTree()" id="treeName"  placeholder="请选择归属单位"/>
								<input name="deptId" type="text" id="treeId" hidden="hidden"/>
							</li>

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="roadnet:baseRoadwaysection:export">
						<i class="fa fa-download"></i> 导出
				</a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var detailFlag = [[${@permission.hasPermi('roadnet:baseRoadwaysection:detail')}]];
		var mapFlag = [[${@permission.hasPermi('roadnet:baseRoadwaysection:map')}]];
        var prefix = ctx + "roadnet/baseRoadwaysection";
		//获取行政区划编码
		var datas_depts=[[${@dept.getDept()}]];
        $(function() {
            var options = {
                url: prefix + "/list",
				detailUrl: prefix + "/roadwaySection/{id}",
				mapUrl: prefix + "/roadwaymap/{id}",
				exportUrl: prefix + "/export",
                modalName: "路段",
		        showExport: true,
				striped: true,//斑马线
                columns: [{
		            checkbox: true
		        },
				{
					field : 'roadcode', 
					title : '道路编码',
					sortable: true
				},
				{
					field : 'roadname', 
					title : '道路名称',
					sortable: true
				},
				{
					field : 'startnum',
					title : '开始桩号',
					sortable: true,
					formatter: function (value, row, index) {
						return convertToKPlus(value);
					}
				},
				{
					field : 'endnum',
					title : '结束桩号',
					sortable: true,
					formatter: function (value, row, index) {
						return convertToKPlus(value);
					}
				},
				{
					field : 'deptId',
					title : '所属乡镇',
					sortable: true,
					formatter: function(value, row, index) {
						return selectDeptLabel(datas_depts, value);
					}
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
						actions.push('<a class="btn btn-success btn-xs ' + mapFlag + '" href="#" onclick="$.operate.map(\'' + row.roadcode + '\')"><i class="fa fa-edit"></i>查看地图</a> ');
		            	actions.push('<a class="btn btn-success btn-xs ' + detailFlag + '" href="#" onclick="$.operate.detail(\'' + row.roadcode + '\')"><i class="fa fa-edit"></i>查看路段</a> ');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);

            var  convertToKPlus=function(num) {
				return 'K' + num.toFixed(3).replace('.', '+');
			}
			var selectDeptLabel=function(datas, value) {
				var actions = [];
				$.each(datas, function(index, dept) {
					if (dept.deptId == ('' + value)) {
						var listClass = "";
						actions.push($.common.sprintf("<span class='%s'>%s</span>", listClass, dept.deptName));
						return false;
					}
				});
				return actions.join('');
			}
		});/*用户管理-新增-选择部门树*/
		function selectDeptTree() {
			var treeId = $("#treeId").val();
			var deptId = $.common.isEmpty(treeId) ? "320000" : $("#treeId").val();
			var url = ctx + "system/dept/selectDeptTree/" + deptId;
			var options = {
				title: '选择部门',
				width: "380",
				url: ctx + "system/dept/selectDeptTree/" + deptId,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}


		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			if ($.tree.notAllowParents(tree)) {
				var body = layer.getChildFrame('body', index);
				$("#treeId").val(body.find('#treeId').val());
				$("#treeName").val(body.find('#treeName').val());
				layer.close(index);
			}
		}
	</script>
</body>
</html>